package com.singzi.testCase;

import org.junit.Test;

import java.security.Key;
import java.util.*;

public class HashTest {
    @Test
    public void test01() {
//        HashMap<Integer, String> Sites = new HashMap<Integer, String>();
////         添加键值对
//        Sites.put(1, "Google");
//        Sites.put(2, "Runoob");
//        Sites.put(3, "Taobao");
//        Sites.put(4, "Zhihu");
//        System.out.println(Sites);
//        System.out.println(Sites.get(3));
        HashMap<String, Integer> Sites = new HashMap<String, Integer>();
        Sites.put("google", 100);
//        System.out.println(Sites.get("google"));
        HashMap<Object, Integer> roman = new HashMap<Object, Integer>();
        roman.put("123123", 100);
        roman.put('1', 100);
        System.out.println(roman.get('1'));
        System.out.println(roman.get("123123"));
    }
    @Test
    public void test02(){
        HashMap<int[],Integer> hashMap = new HashMap<>();
        int []temp = new int[2];
        temp[1] = 1;
        int []temp1 = new int[2];
        temp1[1] = 1;
        hashMap.put(temp, 1);
        System.out.println(hashMap.get(temp1));
    }
    @Test
    public void test03(){
        HashMap<Integer, Integer> hashMap = new LinkedHashMap<>();
        hashMap.put(3,5);
//        hashMap.put(6,8);
//        hashMap.put(1,2);
//        System.out.println(hashMap.keySet());
        hashMap.remove(3);
        hashMap.put(2,4);
        System.out.println(hashMap);
        int count = 0;
        for(Integer value:hashMap.values()){
            count += value;
        }
        for (Integer key:hashMap.keySet())
        {
            System.out.println(key);
        }
        System.out.println(count);

    }
    @Test
    public void testOrderHash(){
        LinkedHashSet<Integer> hashSet = new LinkedHashSet<Integer>();
        hashSet.add(1);
        hashSet.add(5);
        hashSet.add(2);
        hashSet.add(8);
        for(Integer num:hashSet){
            System.out.println(num);
        }
    }
    @Test
    public void treeMapTest(){
        TreeMap<Integer, Integer> treeMap = new TreeMap<>();
        treeMap.firstKey();
        treeMap.lastKey();
//        treeMap.keySet()
        treeMap.put(1,2);
        treeMap.put(3,3);
        for (Map.Entry<Integer, Integer> entry : treeMap.entrySet()) {
            int freq = entry.getValue();
//            entry.getKey()
            System.out.println(freq);
        }


        System.out.println(treeMap.ceilingKey(2));
        System.out.println(treeMap.floorKey(2));
    }
    @Test
    public void getObj(){
        HashSet<Integer> set = new HashSet<>();
        set.add(1);
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.remove(new Integer(1));
        list.get(0);
    }
    @Test
    public void test04(){
        HashMap<Integer,Integer> map = new HashMap<>();
        HashSet<Integer>set = new HashSet<>();
        set.add(null);
        map.put(null, 1);
        map.put(1, null);
        System.out.println(map.get(null));
        System.out.println(map.get(1));
    }
}
